import { AcModal } from '../modal';
const initValue = () => {
  return {
    route: {},
    api: {},
    component: {},
  };
};
let authKeyData = initValue();
export const setInit = () => {
  authKeyData = initValue();
};
export const checkSameAuth = (
  auth: AcModal,
  type: 'route' | 'api' | 'component' | 'all' = 'route',
) => {
  if (!auth) {
    return;
  }
  const key = (typeof auth === 'string' ? auth : auth.key) || '';
  let authDataArray = [];
  if (type === 'all') {
    authDataArray.push(authKeyData.api, authKeyData.component);
  } else {
    authDataArray.push(authKeyData[type]);
  }
  const result = authDataArray.some(item => {
    return !!item[key];
  });
  if (result) {
    throw new Error(`包含相同的key:${key},type:${type}`);
  }
  authDataArray.forEach(item => {
    item[key] = true;
  });
};
